﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1.Models
{
    public class GalleryModelBuilder
    {
        private const string ImagesDirectoryPath = "../StaticContent/Images/";
        private const string ImageExtension = ".JPG";
        private const string Separator = "/";

        private readonly GalleryModel galleryModel;

        public GalleryModelBuilder(GalleryModel galleryModel, BlockModel blockModel)
        {           
            this.galleryModel = galleryModel;
            this.galleryModel.Block = blockModel;
        }

        public GalleryModelBuilder Called(String galleryName)
        {
            galleryModel.Name = galleryName;
            return this;
        }

        public GalleryModelBuilder AndCountOfPictures(int countOfPictures)
        {
            galleryModel.ImagesCount = countOfPictures;
            BuildGallery();
            return this;
        }

        public static implicit operator BlockModel(GalleryModelBuilder galleryModelBuilder)
        {
            galleryModelBuilder.galleryModel.Block.Gallery = galleryModelBuilder.galleryModel;
            return galleryModelBuilder.galleryModel.Block;
        }

        private void BuildGallery()
        {
            galleryModel.ImageCollection = new List<ImageModel>();
            for (int i = 1; i <= galleryModel.ImagesCount; i++)
            {
                var imagePath = ImagesDirectoryPath + galleryModel.Name + Separator + i + ImageExtension;
                galleryModel.ImageCollection.Add(new ImageModel(imagePath, "Some description..."));
            }
        }
    }
}
